﻿using System.Web.Mvc;
using PTop.Application.Questionnaire;
using PTop.Code;
using PTop.Domain.Entity.Questionnaire;

namespace PTop.Web.Areas.Questionnaire.Controllers
{
    /// <summary>
    /// 调查问卷Controller
    /// </summary>	
    public class QnPaperController : ControllerBase
    {
        private QnPaperApp _app = new QnPaperApp();

        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetGridJson(Pagination pagination, string keyword)
        {
            var data = _app.GetList(pagination, keyword);
            return PageContent(pagination.records, pagination.rows, data);
        }
        /// <summary>
        /// 获取未发布的调查问卷
        /// </summary>
        /// <param name="keyword"></param>
        /// <returns></returns>
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetUnreleaseGridJson(string keyword)
        {
            var data = _app.GetUnreleaseList(keyword);
            return Content(data.ToJson());
        }
        [HttpGet]
        [HandlerAjaxOnly]
        public ActionResult GetFormJson(string keyValue)
        {
            var data = _app.GetForm(keyValue);
            return Content(data.ToJson());
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [ValidateAntiForgeryToken]
        public ActionResult SubmitForm(QnPaperEntity entity, string keyValue)
        {
            _app.SubmitForm(entity, keyValue);
            return Success("操作成功。");
        }
        [HttpPost]
        [HandlerAjaxOnly]
        [HandlerAuthorize]
        [ValidateAntiForgeryToken]
        public ActionResult DeleteForm(string keyValue)
        {
            _app.Delete(keyValue);
            return Success("删除成功。");
        }
        /// <summary>
        /// 问卷统计
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public ActionResult Statistics(string pid)
        {
            ViewBag.PId = pid;
            return View();
        }
    }
}